//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.ky;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.DicShopCodeDao;
import com.aidong.dao.wills.DicTranCodeDao;
import com.aidong.dao.wills.KyComboCodeDao;
import com.aidong.dao.wills.PtPriceDao;
import com.aidong.model.wills.DicShopCode;
import com.aidong.model.wills.KyComboCode;
import com.aidong.web.controller.BaseController;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"kyCombo"})
public class KyComboCodeController extends BaseController {
    @Resource
    KyComboCodeDao kyComboCodeDao;
    @Resource
    DicShopCodeDao dicShopCodeDao;
    @Resource
    PtPriceDao ptPriceDao;
    @Resource
    DicTranCodeDao dicTranCodeDao;

    public KyComboCodeController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return new ModelAndView("ky/combo/list");
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "name",required = false) String name, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        ConditionMap cd1 = new ConditionMap(1);
        if(!this.chkNull(name)) {
            cd1.like("code", "%" + name + "%");
            cd1.like("chName", "%" + name + "%");
            cd.addSub(cd1);
        }

        this.kyComboCodeDao.queryPageList(pg, cd, (new OrderSet()).asc("code"));
        ModelAndView mv = new ModelAndView("ky/combo/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"add"})
    public ModelAndView add() {
        KyComboCode combo = new KyComboCode();
        combo.setOverDueUse(Integer.valueOf(1));
        combo.setStatus(Integer.valueOf(1));
        List shopList = this.dicShopCodeDao.getAllShopList();
        Iterator mv = shopList.iterator();

        while(mv.hasNext()) {
            DicShopCode shop = (DicShopCode)mv.next();
            shop.setStatus(Integer.valueOf(0));
        }

        ModelAndView mv1 = new ModelAndView("ky/combo/edit");
        mv1.addObject("combo", combo);
        mv1.addObject("shopList", shopList);
        mv1.addObject("timeUnit", this.getTypeList("timeUnit"));
        mv1.addObject("_oper", "add");
        return mv1;
    }

    @RequestMapping({"_add"})
    @ResponseBody
    public String _add(@ModelAttribute("combo") KyComboCode combo, @RequestParam(value = "shops",required = false) String shops) {
        if(this.chkNull(combo.getCode())) {
            return this.getResult(false, "请输入编号");
        } else if(this.chkNull(combo.getChName())) {
            return this.getResult(false, "请输入名称");
        } else {
            if(this.chkNullZ(combo.getOverDueUse())) {
                combo.setOverDueUse(Integer.valueOf(0));
            }

            if(this.chkNullZ(combo.getStatus())) {
                combo.setStatus(Integer.valueOf(1));
            }

            if(this.kyComboCodeDao.exists(combo.getCode())) {
                return this.getResult(false, "编号已存在");
            } else {
                combo.setCreateUser(this.getLoginUserCode());
                combo.setCreateTime(new Date());
                combo.setUpdateTime(new Date());
                ArrayList shopList = new ArrayList();
                if(!this.chkNull(shops)) {
                    String[] e = shops.split(",");
                    String[] arr$ = e;
                    int len$ = e.length;

                    for(int i$ = 0; i$ < len$; ++i$) {
                        String s = arr$[i$];
                        if(!this.chkNull(s)) {
                            shopList.add(s.trim());
                        }
                    }
                }

                try {
                    this.kyComboCodeDao.addKyCombo(combo, shopList);
                    this.reloadTypeList("kyComboName");
                    this.addUserLog("新增K-Yoga套餐", "编号:" + combo.getCode() + ",名称:" + combo.getChName());
                } catch (Exception var9) {
                    this.log.error("add kycombo", var9);
                    return this.getResult(false, "保存发生错误");
                }

                return this.getResult(true, "保存完成");
            }
        }
    }

    @RequestMapping({"edit"})
    public ModelAndView edit(@RequestParam("code") String code) {
        KyComboCode combo = (KyComboCode)this.kyComboCodeDao.getById(code);
        if(combo == null) {
            return this.showAlert("没有这个记录");
        } else {
            List shopList = this.kyComboCodeDao.getKyComboShopList(code, true);
            ModelAndView mv = new ModelAndView("ky/combo/edit");
            mv.addObject("combo", combo);
            mv.addObject("shopList", shopList);
            mv.addObject("timeUnit", this.getTypeList("timeUnit"));
            mv.addObject("_oper", "edit");
            return mv;
        }
    }

    @RequestMapping({"_edit"})
    @ResponseBody
    public String _edit(@ModelAttribute("combo") KyComboCode combo, @RequestParam(value = "shops",required = false) String shops) {
        if(this.chkNull(combo.getCode())) {
            return this.getResult(false, "请输入编号");
        } else if(this.chkNull(combo.getChName())) {
            return this.getResult(false, "请输入名称");
        } else {
            if(this.chkNullZ(combo.getOverDueUse())) {
                combo.setOverDueUse(Integer.valueOf(0));
            }

            if(this.chkNullZ(combo.getStatus())) {
                combo.setStatus(Integer.valueOf(1));
            }

            KyComboCode combo1 = (KyComboCode)this.kyComboCodeDao.getById(combo.getCode());
            if(combo1 == null) {
                return this.getResult(false, "没有这个记录");
            } else {
                combo1.setChName(combo.getChName());
                combo1.setChargeAmount(combo.getChargeAmount());
                combo1.setPresentAmount(combo.getPresentAmount());
                combo1.setValids(combo.getValids());
                combo1.setValidUnit(combo.getValidUnit());
                combo1.setOverDueUse(combo.getOverDueUse());
                combo1.setActiveTime(combo.getActiveTime());
                combo1.setInactiveTime(combo.getInactiveTime());
                combo1.setNote(combo.getNote());
                combo1.setStatus(combo.getStatus());
                combo1.setUpdateTime(new Date());
                ArrayList shopList = new ArrayList();
                if(!this.chkNull(shops)) {
                    String[] e = shops.split(",");
                    String[] arr$ = e;
                    int len$ = e.length;

                    for(int i$ = 0; i$ < len$; ++i$) {
                        String s = arr$[i$];
                        if(!this.chkNull(s)) {
                            shopList.add(s.trim());
                        }
                    }
                }

                try {
                    this.kyComboCodeDao.updateKyCombo(combo1, shopList);
                    this.reloadTypeList("kyComboName");
                    this.addUserLog("修改K-Yoga套餐", "编号:" + combo.getCode() + ",名称:" + combo.getChName());
                } catch (Exception var10) {
                    this.log.error("edit kycombo", var10);
                    return this.getResult(false, "保存发生错误");
                }

                return this.getResult(true, "保存完成");
            }
        }
    }

    @RequestMapping({"_del"})
    @ResponseBody
    public String _del(@RequestParam("code") String code) {
        KyComboCode combo = (KyComboCode)this.kyComboCodeDao.getById(code);
        if(combo == null) {
            return this.getResult(false, "没有这个记录");
        } else {
            try {
                this.kyComboCodeDao.updateStatus(code, 0);
                this.reloadTypeList("kyComboName");
                this.addUserLog("删除K-Yoga套餐", "编号:" + combo.getCode() + ",名称:" + combo.getChName());
            } catch (Exception var4) {
                this.log.error("del kycombo", var4);
                return this.getResult(false, "删除发生错误");
            }

            return this.getResult(true, "删除成功");
        }
    }
}
